//
//  CZStatusTopView.swift
//  swiftweibo
//
//  Created by Apple on 15/11/28.
//  Copyright © 2015年 tzw. All rights reserved.
//

import UIKit

class CZStatusTopView: UIView {
    // MARK:设置数据
    var status:CZStatus?{
        didSet{
            /// 为控件添加数据
            // 添加头像
            if let profile_image_url = status?.user?.profile_image_url{
                iconView.sd_setImageWithURL(NSURL(string: profile_image_url), placeholderImage: UIImage(named: "avatar"))
            }
            // 设置用户名
            nameLabel.text = status?.user?.screen_name
            // 时间
            timeLabel.text = status?.created_at
            // 来源
            sourceLabel.text = status?.source
            // 微博认证
            verifiedImageView.image = status?.user?.verifiedImage
            // 设置会员等级
            mbrankImageView.image = status?.user?.mbrankImage
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    // 构造方法
    override init(frame: CGRect) {
        super.init(frame: frame)
        // 准备UI
        prepareUI()
    }
    // 添加UI
    private func prepareUI(){
        // 添加控件
        addSubview(separatView)
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(mbrankImageView)
        addSubview(verifiedImageView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        // 添加约束
        // 侵害视图
        separatView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 10))
        // 头像
        iconView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: separatView, size: CGSize(width: 35, height: 35), offset: CGPoint(x: CZStatusCellMargin, y: CZStatusCellMargin))
        // 名字
        nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: CZStatusCellMargin, y: 0))
        // 会员图标
        mbrankImageView.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: nameLabel, size: CGSize(width: 14, height: 14), offset: CGPoint(x: CZStatusCellMargin, y: 0))
        // 时间
        timeLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: CZStatusCellMargin, y: 0))
        // 来源
        sourceLabel.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: timeLabel, size: nil, offset: CGPoint(x: CZStatusCellMargin, y: 0))
        // 认证类型
        verifiedImageView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: CGSize(width: 17, height: 17), offset: CGPoint(x: 8.5, y: 8.5))
    }

    
    
    
    // MARK: - 懒加载
    // 头像
    private lazy var iconView:UIImageView = UIImageView(image: UIImage(named: "avatar"))
    // 名字
    private lazy var nameLabel: UILabel = UILabel(color: UIColor.darkGrayColor(), fontSize: 14)
    // 会员等级图标
    private lazy var mbrankImageView: UIImageView = UIImageView()
    // 认证类型图标
    private lazy var verifiedImageView: UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    // 时间
    private lazy var timeLabel: UILabel = UILabel(color: UIColor.orangeColor(), fontSize: 9)
    
    // 来源
    private lazy var sourceLabel: UILabel = UILabel(color: UIColor.lightGrayColor(), fontSize: 9)
    // 分割视图
    private lazy var separatView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(white: 0.9, alpha: 1)
        return view
    }()
    

}
